﻿@model WebGioiThieu.Models.Tour
@{
    ViewBag.Title = Model.TieuDe;
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<h2 class="content-head">@Html.DisplayFor(model => model.TieuDe)</h2>

<script type="text/javascript">
    $(document).ready(function () {
        $('#btn_comfirm').click(function () {
            //alert($('#newcommentform').valid());
            if ($('#newcommentform').valid()) {
                var tourId = $('#tourId').val();
                var name = $('#com_HoTen').val();
                var email = $('#com_Email').val();
                var content = $('#com_NoiDung').val();

                var dataPost = "Email=" + email + "&HoTen=" + name + "&tourId=" + tourId + "&NoiDung=" + content;

                $.ajax({
                    type: "POST",
                    url: "/Comment/CreateComment?ajaxVar=true",
                    data: dataPost,
                    success: function (data) {
                        data = "var rs = " + data + ";";
                        eval(data);
                        //alert(data);
                        if (rs.rs) {

                            var div_info = $("<div>").addClass("comment-info").html(name).append('(').append(email).append(')');
                            var div_content = $("<div>").addClass("comment-content").html(content);
                            $("#comment-list").append(div_info).append(div_content);
                            alert("Bình luận đã được gửi");


                        }
                        else {
                            alert("error");
                        }


                    }
                });
            }
            document.getElementById('com_HoTen').value = "";
            document.getElementById('com_Email').value = "";
            document.getElementById('com_NoiDung').value = "";
            return false;
        });
    });
</script>
<div class="article">

    <div class="display-label">Người đăng: @Model.MemberID</div>

    <div class="display-field">
        @Html.DisplayFor(model => model.PhanModau)
    </div>

    <hr />
    <div class="display-field">
        @(new HtmlString(Model.NoiDung))
    </div>
    Lượt xem:@Html.DisplayFor(model => model.LuotXem) | Cập nhật lần cuối:@Html.DisplayFor(model => model.NgayCapNhat)
    <div class="clear"></div>
    <div id="comment-list">
        <p>Bình luận cho bài viết:</p>
        @Html.Partial("_CommentList")
    </div>
    <div class="clear"></div>
    <div class="comment-add">
        @using (Html.BeginForm("CreateComment", "Comment", FormMethod.Post, new { id = "newcommentform" }))
        {
            var com = ViewBag.comment as WebGioiThieu.Models.Comment;
            @Html.ValidationSummary(true)
                <input type="hidden" id="tourId" name="tourId" value="@Model.ID"/>
                @Html.TextBoxFor(c => com.HoTen, new { placeholder = "Tên" })@Html.ValidationMessageFor(c => com.HoTen)<br />
                @Html.TextBoxFor(c => com.Email, new { placeholder = "Email" })@Html.ValidationMessageFor(c => com.Email)<br />
                @Html.EditorFor(c => com.NoiDung, new { placeholder = "Viết nội dung bình luận ở đây" })@Html.ValidationMessageFor(c => com.NoiDung)<br />
                <input type="submit" id="btn_comfirm" value="Gửi" />
        }
        <div class="clear"></div>
    </div>
    <div class="clear"></div>
</div>
<div class="clear"></div>
